package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.TLogistics;
import com.smz.service.TLogisticsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TLogisticsController {

    @Autowired
    private TLogisticsService tLogisticsService;

    @RequestMapping(value = "/tLogistics/all",method = RequestMethod.GET)
    public ResponseEntity<List<TLogistics>> findTLogisticsAllGgy(){
        List<TLogistics> listTLogistics = tLogisticsService.list();
        return ResponseEntity.ok(listTLogistics);
    }

    @ApiOperation("物流公司分页查询")
    @GetMapping("/tLogistics/{current}/{size}")
    public ResponseEntity<IPage<TLogistics>> findTLogisticsPage(@PathVariable("current") int current,
                                                                @PathVariable("size") int size){
        IPage<TLogistics> page = tLogisticsService.findTLogisticsPage(current,size);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("物流公司名字分页查询")
    @GetMapping("/tLogisticsName/{current}/{size}/{logisticsName}")
    public ResponseEntity<IPage<TLogistics>> findTLogisticsPageName(@PathVariable("current") int current,
                                                                    @PathVariable("size") int size,
                                                                    @PathVariable("logisticsName") String logisticsName){
        IPage<TLogistics> page = tLogisticsService.findTLogisticsPageName(current,size,logisticsName);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("物流公司ID分页查询")
    @GetMapping("/tLogisticsId/{current}/{size}/{logisticsId}")
    public ResponseEntity<IPage<TLogistics>> findTLogisticsPageId(@PathVariable("current") int current,
                                                                  @PathVariable("size") int size,
                                                                  @PathVariable("logisticsId") int logisticsId){
        IPage<TLogistics> page = tLogisticsService.findTLogisticsPageId(current,size,logisticsId);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("添加物流公司信息")
    @PostMapping("/tLogistics")
    public ResponseEntity<String> addTLogistics(@RequestBody TLogistics tLogistics){
        tLogisticsService.saveOrUpdate(tLogistics);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("修改物流公司信息")
    @PutMapping("/tLogistics")
    public ResponseEntity<String> modifyTLogistics(@RequestBody TLogistics tLogistics){
        tLogisticsService.saveOrUpdate(tLogistics);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("删除物流公司信息")
    @DeleteMapping("/tLogistics/{id}")
    public ResponseEntity<String> removeTLogistics(@PathVariable("id") int id){
        tLogisticsService.removeById(id);
        return ResponseEntity.ok("ok");
    }

}
